import Router from "@koa/router";
import type { ControllerCallType } from "@/utils/controller";
import AuthController from "@/controller/auth";
import authenticate from "@/middlewares/authenticate";
import authorize from "@/middlewares/authorize";
import { PERMISSION_MAP } from "@/config";

export default (router: Router, controller: ControllerCallType) => {
  const r = new Router();
  const c = new AuthController();

  r.prefix("/auth");
  r.post("/login", controller(c, "login"));
  r.post("/register", controller(c, "register"));
  r.get(
    "/profile",
    authenticate,
    authorize([PERMISSION_MAP.UserProfile]),
    controller(c, "profile")
  );

  router.use(r.routes()).use(r.allowedMethods());
};
